package com.watchthelan.web.interceptors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.watchthelan.domain.Administrator;

public class AuthInterceptor extends HandlerInterceptorAdapter {
	protected final Log logger = LogFactory.getLog(getClass());
	
	public boolean preHandle(HttpServletRequest request,
            HttpServletResponse response,
            Object handler) throws Exception {

        HttpSession session = request.getSession();
        Administrator administrator = (Administrator) session.getAttribute("administrator");
        if (administrator != null) {
            return true;
        } else {
        	logger.info("administrator is null, have to login");
            response.sendRedirect("login.htm");
            return false;
        }
    }

}
